home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Languguage OS 2
/
Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO
/
gnu
/
dejagnu.lha
/
dejagnu-1.0.1
/
dejagnu
/
runtest.exp
< prev
next >
Wrap
Text File
|
1993-05-26
|
19KB
|
632 lines
# Test Framework Driver
# Copyright (C) 1988, 1990, 1991, 1992, 1993 Free Software Foundation, Inc.
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
# Please email any bugs, comments, and/or additions to this file to:
# bug-dejagnu@prep.ai.mit.edu
# This file was written by Rob Savoye. (rob@cygnus.com)
set frame_version 1.0.1
#
# trap some signals so we know whats happening. These definitions are only
# temporary until we read in the library stuff
#
trap { send_user "\nterminated\n"; exit 1 } SIGTERM
trap { send_user "\ninterrupted by user\n"; exit 1 } SIGINT
trap { send_user "\nsegmentation violation\n"; exit 1 } SIGSEGV
trap { send_user "\nsigquit\n"; exit 1 } SIGQUIT
#
# initialize a few global variables used by all tests
#
set do_a_diff 0 ;# flag enabling diff of summary logs
set mail_logs 0 ;# flag for mailing of summary and diff logs
set psum_file "latest" ;# file name of previous summary to diff against
set passcnt 0 ;# number of testcases that passed
set failcnt 0 ;# number of testcases that failed
set xfailcnt 0 ;# number of testcases expected to fail which did
set xpasscnt 0 ;# number of testcases that passed unexpectedly
set exit_status 0 ;# exit code returned by this program
set xfail_flag 0
set xfail_prms 0
set sum_file "" ;# name of the file that contains the summary log
set base_dir "" ;# the current working directory
set logname "" ;# the users login name
set prms_id 0
set bug_id 0
set test_name "" ;# name of the test driver to be run
set dir "" ;# temp variable for directory names
set srcdir "." ;# source directory containing the test suite
set ignoretests "" ;# list of tests to not execute
set target "" ;# type of architecture to run tests on
set host "" ;# type of architecture to run tests from
set objdir "." ;# directory where test case binaries live
set target_triplet "native" ;# canonical triplet target name
set makevars ""
#
# some convenience abbreviations
#
if ![info exists hex] then {
set hex "0x\[0-9A-Fa-f\]+"
}
if ![info exists decimal] then {
set decimal "\[0-9\]+"
}
#
# set the base dir (current working directory)
#
if [string match "" $base_dir] then {
set base_dir [exec pwd]
if [string match "*Command not found*" $base_dir] then {
if [info exists env(PWD)] then {
set base_dir $env(PWD)
} else {
set base_dir ""
}
if [string match "" $base_dir] then {
puts stderr "ERROR: couldn't get the current directory" ; exit -1
}
}
}
#
# These are tested in case they are not initialized in site.exp. They are
# tested here instead of the init module so they can be overridden by command
# line options.
#
if ![info exists all_flag] then {
set all_flag 0
}
if ![info exists binpath] then {
set binpath ""
}
if ![info exists debug] then {
set debug 0
}
if ![info exists options] then {
set options ""
}
if ![info exists outdir] then {
set outdir "."
}
if ![info exists reboot] then {
set reboot 1
}
if ![info exists runtests] then {
set runtests ""
}
if ![info exists tracelevel] then {
set tracelevel 0
}
if ![info exists verbose] then {
set verbose 0
}
#
# get the users login name
#
if [string match "" $logname] then {
set logname [exec whoami]
if [string match "*Command not found*" $logname] then {
set logname [exec who am i]
if [string match "*Command not found*" $logname] then {
send_user "ERROR: couldn't get the users login name\n" ; exit -1
} else {
set logname [lindex [split $logname " !"] 1]
}
}
}
#
# parse configuration args so the config file can get loaded. Otherwise
# command line options can't override the settings.
#
set match 0
set argc [ llength $argv ]
for { set i 1 } { $i < $argc } { incr i } {
global target_triplet
global host_triplet
set sub_arg [ lindex $argv $i ]
case $sub_arg in {
{"[-+]ho*" "[-+][-+]ho*"} { # (--host) the host configuration
incr i
set host_triplet [lindex $argv $i]
continue
}
{"[-+]ta*" "[-+][-+]ta*"} { # (--target) the target configuration
incr i
set target_triplet [lindex $argv $i]
# override local site file and load the configuration of a different target
}
}
}
#
# find where the config file is. ALL are sourced in order. The order is
# first see if one is installed. Then look for for a parallel "dejagnu"
# directory up one or two directories. Finally source one in the current
# dir if it exists.
#
set execpath "[file dirname [lindex $argv 0]]"
set libdir [file dirname $execpath]/dejagnu
if [string match "." $objdir] then {
set objdir $base_dir
}
foreach dir "$libdir/$target_triplet [file dirname $objdir]/dejagnu [file dirname [file dirname $objdir]]/dejagnu ." {
#send_user "Looking for config file $dir/site.exp\n"
if [file exists $dir/site.exp] then {
#send_user "Sourcing config file $dir/site.exp\n"
catch "source $dir/site.exp" tmp
}
}
#
# parse the command line arguments
#
set match 0
set argc [ llength $argv ]
for { set i 1 } { $i < $argc } { incr i } {
set sub_arg [ lindex $argv $i ]
case $sub_arg in {
{"[-+]ho*" "[-+][-+]ho*"} { # (--host) the host configuration
incr i
if $verbose>1 then { send_user "The host is now $host_triplet\n" }
continue
}
{"[-+]ta*" "[-+][-+]ta*"} { # (--target) the target configuration
incr i
if $verbose>1 then { send_user "The target is now $target_triplet\n" }
continue
}
{"[-+]a*" "[-+][-+]a*"} { # (--all) print all test output to screen
set all_flag 1
if $verbose>1 then { send_user "Print all test output to screen\n" }
continue
}
{"[-+]b*" "[-+][-+]b*"} { # (--baud) the baud to use for a serial line
incr i
set baud [lindex $argv $i]
if $verbose>1 then { send_user "The baud rate is now $baud\n" }
continue
}
{"[-+]co*" "[-+][-+]co*"} { # (--connect) the connection mode to use
incr i
set connectmode [lindex $argv $i]
if $verbose>1 then { send_user "Comm method is $connectmode\n" }
continue
}
{"[-+]de*" "[-+][-+]de*"} { # (--debug) expect internal debugging
catch "exec rm ./dbg.log"
debug -f dbg.log 0
if $verbose>1 then { send_user "Expect Debugging is ON \n" }
continue
}
{"[-+]di*" "[-+][-+]di*"} { # (--diff) diff the summary files
send_user "Sorry, --diff unimplemented\n"
#set do_a_diff 1
#incr i
#set psum_file [lindex $argv $i]
#if $verbose>1 then { send_user "Diff summary files when done\n" }
continue
}
{"[-+]m*" "[-+][-+]m*"} { # (--mail) mail the output
incr i
set mailing_list [lindex $argv $i]
set mail_logs 1
if $verbose>1 then { send_user "Mail results to $mailing_list\n" }
continue
}
{"[-+]no*" "[-+][-+]no*"} { # (--noreboot) Don't reboot the target
set reboot 0
if $verbose>1 then { send_user "Won't reboot the target\n" }
continue
}
{"[-+]ob*" "[-+][-+]ob*"} { # (--objdir) where the test case object code lives
incr i
set objdir [lindex $argv $i]
if $verbose>1 then { send_user "Using test binaries in $objdir\n" }
continue
}
{"[-+]ou*" "[-+][-+]ou*"} { # (--outdir) where to put the output files
incr i
set outdir [lindex $argv $i]
if $verbose>1 then { send_user "Test output put in $outdir\n" }
continue
}
{"[-+]ru*" "[-+][-+]ru*"} { # (--runtest) specify test names to run
incr i
set runtests [lindex $argv $i]
if $verbose>1 then { send_user "Running only tests $runtests\n" }
continue
}
{"[-+]i*" "[-+][-+]i*"} { # (--ignore) specify test names to exclude
incr i
set ignoretests [lindex $argv $i]
if $verbose>1 then { send_user "Ignoring test $ignoretests\n" }
continue
}
{"[-+]sr*" "[-+][-+]sr*"} { # (--srcdir) where the testsuite source code lives
incr i
set srcdir [lindex $argv $i]
if $verbose>1 then { send_user "Using test sources in $srcdir\n" }
continue
}
{"[-+]st*" "[-+][-+]st*"} { # (--strace) expect trace level
incr i
set tracelevel [ lindex $argv $i ]
strace $tracelevel
if $verbose>1 then { send_user "Source Trace level is now $tracelevel\n" }
continue
}
{"[-+]n*" "[-+][-+]n*"} { # (--name) the target's name
incr i
set targetname [lindex $argv $i]
if $verbose>1 then { send_user "Testing target $targetname\n" }
continue
}
{"[-+]to*" "[-+][-+]to*"} { # (--tool) specify tool name
incr i
set tool [lindex $argv $i]
if $verbose>1 then { send_user "Testing $tool\n" }
continue
}
{"*[-+]V*" "*[-+]vers*"} { # (--version) version numbers
send_user "Expect version is\t$expect_version\n"
send_user "Tcl version is\t\t[ info tclversion ]\n"
send_user "Framework version is\t$frame_version\n"
continue
}
"[A-Z]*=*" { # process makefile style args like CC=gcc, etc...
set tmp [split $sub_arg "="]
set [lindex $tmp 0] [lindex $tmp 1]
if $verbose>1 then {
send_user "[lindex $tmp 0] is now [lindex $tmp 1]\n"
}
append makevars "set [lindex $tmp 0] [lindex $tmp 1];"
unset tmp
continue
}
{"[-+]v*" "[-+][-+]v*" "*[-+]verb*"} { # (--verbose) verbose output
incr verbose
if $verbose then { send_user "Verbose is now at level $verbose\n" }
continue
}
{"[-+]he*" "[-+][-+]he*"} { # (--help) help text
send_user "USAGE: runtest \[options...\]\n"
send_user "\t--all (-a)\t\tPrint all test output to screen\n"
send_user "\t--baud (-b)\t\tThe baud rate\n"
send_user "\t--connect (-co)\t\[type\]\tThe type of connection to use\n"
send_user "\t--debug (-de)\t\tSet expect debugging ON\n"
send_user "\t--diff \[name\]\t\tRun diff between two test runs\n"
send_user "\t--help (-he)\t\tPrint help text\n"
send_user "\t--mail \[name(s)\]\tWho to mail the results to\n"
send_user "\t--noreboot \[name\]\tDon't reboot the target\n"
send_user "\t--objdir \[name\]\t\tThe test suite binary directory\n"
send_user "\t--outdir \[name\]\t\tThe directory to put logs in\n"
send_user "\t--runtest \[name(s)\]\tThe names of specific tests to run\n"
send_user "\t--ignore \[name(s)\]\tThe names of specific tests to ignore\n"
send_user "\t--srcdir \[name\]\t\tThe test suite source code directory\n"
send_user "\t--strace \[number\]\tSet expect tracing ON\n"
send_user "\t--name \[name\]\t\tThe hostname of the target board\n"
send_user "\t--target \[string\]\tThe canonical config name of the target board\n"
send_user "\t--host \[string\]\t\tThe canonical config name of the host machine\n"
send_user "\t--tool\[name(s)\]\t\tRun tests on these tools\n"
send_user "\t--verbose (-v)\t\tEmit verbose output\n"
send_user "\t--version (-V)\t\tEmit all version numbers\n"
send_user "\tMakefile style arguments can also be used, ex. CC=gcc\n\n"
exit 0
}
default { # default
send_user "\nIllegal Argument \"$sub_arg\"\n"
send_user "try \"runtest --help\" for option list\n"
exit 0
}
}
}
#
# check for a few crucial variables
#
if ![info exists tool] then {
send_error "ERROR: No tool specified, use the --tool option\n"
exit 1
}
if ![info exists host_triplet] then {
send_error "ERROR: No host configuration. Check the config file.\n"
exit 1
}
if ![info exists target_triplet] then {
send_error "ERROR: No target configuration. Check the config file.\n"
exit 1
}
#
# initialize a few Tcl variables to something other than their default
#
if $verbose>2 then {
log_user 1
} else {
log_user 0
}
set timeout 10
#
# load_lib -- loads a library by sourcing it. If there a multiple files with
# the same name, they all get sourced in order. The order is first
# look in the install dir, then in a parallel dir in the source tree,
# (up one or two levels), then in the current dir.
#
proc load_lib { file } {
global verbose
global libdir
global srcdir
global base_dir
global execpath
global tool
set found 0
set tmp ""
foreach dir "$libdir $libdir/lib [file dirname [file dirname $srcdir]]/dejagnu/lib $srcdir/lib ." {
if $verbose>2 then {
send_user "Looking for $dir/$file\n"
}
if [file exists $dir/$file] then {
if $verbose>2 then {
send_user "Loading $dir/$file\n"
}
catch "source $dir/$file" tmp
if ![string match "" $tmp] then {
send_user "ERROR: errors in library file $dir/$file\n$tmp\n"
exit 1
} else {
set found 1
}
}
}
if $found==0 then {
send_user "ERROR: Couldn't load $file.\n"
exit 1
}
unset found
unset tmp
}
#
# load the testing framework libraries
#
load_lib utils.exp
load_lib framework.exp
#
#
# set target variables only if needed.
#
if ![isnative] then {
# MVME board running *Bug boot monitor
if [istarget "*-abug-*"] then {
if ![info exists targetname] then {
puts stderr "ERROR: Need a target name for the target board."
puts stderr " Use the --target option\n"
exit 1
}
# the default connect program to use
if ![info exists connectmode] then {
set connectmode "tip"
warning "Using default of $connectmode for target communication."
}
}
# any flavor of vxworks
if [istarget "*-*-vxworks"] then {
# the hostname of the target board
if ![info exists targetname] then {
puts stderr "ERROR: Need a target name for the vxworks board."
puts stderr " Use the --target option\n"
exit 1
}
# the default connect program to use
if ![info exists connectmode] then {
set connectmode "rlogin"
warning "Using default of $connectmode for target communication."
}
}
}
#
# open log files
#
open_logs
clone_output "Test Run By $logname on [exec date]"
clone_output "Target is $target_triplet"
clone_output "Host is $host_triplet"
clone_output "\n\t\t=== $tool tests ===\n"
#
# go find the init file. A local copy is sourced if it is found,
# otherwise the system default one is sourced instead
#
set tool_init $srcdir/config/${target_abbrev}
#
# find the tool init file. This is in the config directory of the tool's
# testsuite directory. These used to all be named $target_os-$tool.exp,
# but as the $tool variable goes away, it's now just $target_os.exp.
#
if [ expr "[file exists ${tool_init}-${tool}.exp] + [file exists ${tool_init}-${tool}.exp] == 2"] then {
catch "source ${tool_init}-${tool}.exp" error
if ![string match "" $error] then {
send_user "ERROR: errors in tool init file ${tool_init}-${tool}.exp\n$error\n"
exit 1
}
verbose "Sourced ${tool_init}-${tool}.exp" 2
} else {
if [file exists ${tool_init}.exp] then {
catch "source ${tool_init}.exp" error
if ![string match "" $error] then {
send_user "ERROR: errors in tool init file ${tool_init}.exp\n$error\n"
exit 1
}
verbose "Sourced ${tool_init}.exp" 2
} else {
catch "source ${tool_init}-${tool}.exp" error
if ![string match "" $error] then {
send_user "ERROR: errors in tool init file ${tool_init}-${tool}.exp\n$error\n"
exit 1
}
verbose "Sourced ${tool_init}-${tool}.exp" 2
} else {
error "There is no tool init file in $srcdir/config"
exit 1
}
}
#
# trap some signals so we know whats happening. These replace the the previous
# ones cause we've now loaded the library stuff
#
trap {
global exit_status
send_error "\nterminated\n"
log_summary
close_logs
cleanup
exit $exit_status
} SIGTERM
trap {
global exit_status
send_error "\ninterrupted by user\n"
log_summary
close_logs
cleanup
exit $exit_status
} SIGINT
trap {
global exit_status
send_error "\nsegmentation violation\n"
log_summary
close_logs
cleanup
exit $exit_status
} SIGSEGV
trap {
global exit_status
send_error "\nsigquit\n"
log_summary
close_logs
cleanup
exit $exit_status
} SIGQUIT
#
# main test execution loop
#
reset_vars
foreach dir [lsort [getdirs $srcdir $tool*]] {
foreach test_name [lsort [find $dir *.exp]] {
set subdir [file dirname [string range ${test_name} [expr [string length $srcdir]+1] end]]
if [string match "" ${test_name}] then {
continue
}
# check to see if the range of tests is limited
if ![string match "" $runtests] then {
if ![expr 0<=[lsearch $runtests [file tail ${test_name}]]] then {
continue
}
}
if ![string match "" $ignoretests] then {
if [expr 0<=[lsearch $ignoretests [file tail ${test_name}]]] then {
continue
}
}
clone_output "Running ${test_name} ..."
set prms_id 0
set bug_id 0
set test_result ""
if [file exists $test_name] then {
catch "source ${test_name}" test_result
if ![string match "" $test_result] then {
if ![string match "0" $test_result] then {
error "Got an error from ${test_name}\n$test_result"
set test_result ""
continue
}
}
} else {
error "$test_name does not exist."
}
}
}
#
# all done, cleanup
#
if {[info procs ${tool}_exit] != ""} then {
${tool}_exit
}
log_summary
close_logs
if $do_a_diff then {
if [diff_logs $psum_file] then {
if $mail_logs then {
mail_file $outdir/$tool.diff $mailing_list "Dejagnu Summary Diff"
}
} else {
if $mail_logs then {
catch "exec mail -s \"Dejagnu - No Differences Found\" $mailing_list < /dev/null"
}
}
} else {
if $mail_logs then {
mail_file $outdir/$tool.sum $mailing_list "Dejagnu Summary Log"
}
}
cleanup
exit $exit_status